#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const int N = 3e5 + 10;
struct Edge
{
	int to;
	ll len;
};
struct
{
	int u, v;
} e[N];
vector<Edge> son[N];
ll diss[N], dist[N], ans;
int dir[N];
void dfss(int x, int fa)
{
	for (Edge to : son[x])
	{
		if (to.to != fa)
		{
			diss[to.to] = diss[x] + to.len;
			dfss(to.to, x);
		}
	}
}
void dfst(int x, int fa)
{
	for (Edge to : son[x])
	{
		if (to.to != fa)
		{
			dist[to.to] = dist[x] + to.len;
			dfst(to.to, x); // 别写成dfss！！！
		}
	}
}
void dirdfss(int x, int fa)
{
	for (Edge to : son[x])
	{
		if (to.to != fa)
		{
			if (diss[to.to] <= dist[to.to])
			{
				dir[to.to] = x;
				ans += diss[to.to];
			}
			dirdfss(to.to, x);
		}
	}
}
void dirdfst(int x, int fa)
{
	for (Edge to : son[x])
	{
		if (to.to != fa)
		{
			if (diss[to.to] > dist[to.to])
			{
				dir[to.to] = x;
				ans += dist[to.to];
			}
			dirdfst(to.to, x); // 别写成dirdfss！！！
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, s, t, i, u, v;
	ll w;
	cin >> n >> s >> t;
	for (i = 1; i < n; ++i)
	{
		cin >> u >> v >> w;
		son[u].push_back({v, w});
		son[v].push_back({u, w});
		e[i] = {u, v};
	}
	dfss(s, 0);
	dfst(t, 0);
	dirdfss(s, 0);
	dirdfst(t, 0);
	cout << ans << '\n';
	for (i = 1; i < n; ++i)
	{
		cout << (e[i].v == dir[e[i].u] ? '1' : (e[i].u == dir[e[i].v] ? '2' : '0'));
	}
	return 0;
}
